package one.bugu.android.demon.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.promeg.pinyinhelper.Pinyin;
import com.juefeng.android.framework.LKUtil;
import com.juefeng.android.framework.common.base.BaseListAdapter;

import java.text.DecimalFormat;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.BGTInfoBean;
import one.bugu.android.demon.bean.CalculationBean;
import one.bugu.android.demon.constant.HttpConstant;

public class CalculationInfoAdapter extends BaseListAdapter<CalculationBean> {

    private Context context;

    public CalculationInfoAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public int getContentLayoutId() {
        return R.layout.item_calculationinfo;
    }

    @Override
    public ViewHolder getViewHolder() {
        return new CalculationInfoAdapter.Holder();
    }

    public class Holder implements ViewHolder<CalculationBean> {

        /**
         * 算力数量
         */
        private TextView calculationNum;

        /**
         * 时间
         */
        private TextView createTime;

        /**
         * 类型
         */
        private TextView tradeTypeName;

        /**
         * 图片类型
         */
        private ImageView typeImg;

        private TextView tv_cal_indate;

        DecimalFormat df = new DecimalFormat("0.00000");

        @Override
        public void initView(View view) {

            calculationNum = view.findViewById(R.id.calculation_num);
            createTime = view.findViewById(R.id.calculation_time);
            tradeTypeName = view.findViewById(R.id.calculation_title);
            typeImg = view.findViewById(R.id.calculationType_img);
            tv_cal_indate = view.findViewById(R.id.tv_cal_indate);
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void initData(CalculationBean calculationBean) {
            tv_cal_indate.setVisibility(View.GONE);
            DecimalFormat df = new DecimalFormat("#");

            //加减标识
            String inOutFlag = calculationBean.getInOutFlag() == 0 ? "+" : "-";
            //名称
            String typeName = Pinyin.toPinyin(calculationBean.getTradeTypeName(), "");
            //文字颜色
            String color = calculationBean.getInOutFlag() == 0 ? "#333333" : "#FE7361";
            //图标
//            LKUtil.getImageLoader().loadImage(String.format(HttpConstant.BASE_IMAGE_URL, typeName), typeImg, R.mipmap.bugu_logo);
            //名称
//            tradeTypeName.setText(calculationBean.getTradeTypeName());
            //时间
            createTime.setText(calculationBean.getCreateTime());
            //数量
            calculationNum.setText(inOutFlag + df.format(calculationBean.getOptNum()));
            calculationNum.setTextColor(Color.parseColor(color));
            //描述, 算力购买时显示
//            if (TextUtils.equals(calculationBean.getTradeTypeId(), "501")
//                    || TextUtils.equals(calculationBean.getTradeTypeId(), "502")) {
//                tv_cal_indate.setVisibility(View.VISIBLE);
//                tv_cal_indate.setText(calculationBean.getFlowDesc());
//            }

            if ("20".equals(calculationBean.getTradeTypeId())) {
                if ("创世用户初始算力值".equals(calculationBean.getTradeTypeName())) {
                    tradeTypeName.setText("创世用户");
                    typeImg.setImageResource(R.mipmap.suanli_chuangshi);
                } else {
                    tradeTypeName.setText("新用户赠送");
                    typeImg.setImageResource(R.mipmap.suanli_zhuce);
                }
            } else if ("10".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("购买");
                typeImg.setImageResource(R.mipmap.yuyin_chongzhi);
            } else if ("40".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("使用扣除");
                typeImg.setImageResource(R.mipmap.yuyin_kouchu);
            } else if ("30".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("邀请奖励");
                typeImg.setImageResource(R.mipmap.yuyin_yaoqing);
            } else if ("50".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("返还");
                typeImg.setImageResource(R.mipmap.yuyin_fanhuan);
            } else if ("60".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("日常登录");
                typeImg.setImageResource(R.mipmap.suanli_denglu);
            } else if ("70".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("农场领取");
                typeImg.setImageResource(R.mipmap.bgt_nongchang);
            } else if ("80".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText("兑换");
                typeImg.setImageResource(R.mipmap.bgt_duihuan_d);
            } else if ("90".equals(calculationBean.getTradeTypeId())) {
                tradeTypeName.setText(calculationBean.getFlowDesc());
                if ("首次设置预警".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_yujing);
                } else if ("关注公众号".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_gognzhognhao);
                } else if ("加客服微信".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_kefu);
                } else if ("新人注册".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_xinren);
                } else if ("每日登录".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.suanli_denglu);
                } else if ("填写邀请码".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.suanli_yaoqingma);
                } else if ("邀请好友".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_yaoqing);
                } else if ("前10000名用户".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_qianyiwan);
                } else if ("关注公众号并绑定手机".contains(calculationBean.getFlowDesc())) {
                    typeImg.setImageResource(R.mipmap.renwu_gognzhognhao);
                }
            } else if ("400".equals(calculationBean.getTradeTypeId())) {
                //小说领取算力
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_task_game);
            } else if ("401".equals(calculationBean.getTradeTypeId())) {
                //游戏领取算力
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_task_book);
            } else if ("501".equals(calculationBean.getTradeTypeId())) {
                //购买算力
                tv_cal_indate.setVisibility(View.VISIBLE);
                tv_cal_indate.setText(calculationBean.getFlowDesc());
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_magic_cal_icon);
            } else if ("502".equals(calculationBean.getTradeTypeId())) {
                //购买算力到期
                tv_cal_indate.setVisibility(View.VISIBLE);
                tv_cal_indate.setText(calculationBean.getFlowDesc());
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_magic_cal_icon);
            } else if ("601".equals(calculationBean.getTradeTypeId())) {
                //财务减款
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_magic_cal_icon);
            } else if ("600".equals(calculationBean.getTradeTypeId())) {
                //财务加款
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_magic_cal_icon);
            } else {
                tradeTypeName.setText(calculationBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_magic_cal_icon);
            }
        }

        @Override
        public void initEvent(CalculationBean calculationBean) {

        }
    }
}
